clims = [0.5 4]

exp = [1:10];

for site_nbr = 1:3
    site_nbr_ind(site_nbr,1)=size(proj_meta(site_nbr).rd(1).act,1)
end

site_nbr= [1:3]

for site_nbr = 1:3
    for exp = 1:10
        for ind = 1:site_nbr_ind(site_nbr,1)
        ddd=corrcoef(proj_meta(site_nbr).rd(exp).act(ind,:),proj_meta(site_nbr).rd(exp).velM(1,:));
        site(site_nbr).corr_matrix_lin(exp,ind)=abs(ddd(1,2));
        end
    end
end

for site_nbr = 1:3
    [aaa,site(site_nbr).corr_matrix_lin_ind]=sort(site(site_nbr).corr_matrix_lin,2)
end

for site_nbr = 1:3
    for exp = 1:10
        for ind = 1:site_nbr_ind(site_nbr,1)
        ccc=corrcoef(proj_meta(site_nbr).rd(exp).act(ind,:),proj_meta(site_nbr).rd(exp).velP(1,:));
        site(site_nbr).corr_matrix_2D(exp,ind)=abs(ccc(1,2));
        end
    end
end

for site_nbr = 1:3
    [aaa,site(site_nbr).corr_matrix_2D_ind]=sort(site(site_nbr).corr_matrix_2D,2)
end

for site_nbr = 1:3
    site(site_nbr).mean_corr_lin=mean(site(site_nbr).corr_matrix_lin,2)
    site(site_nbr).mean_corr_2D=mean(site(site_nbr).corr_matrix_2D,2)
end

xxx = [1:40000]

% plot heat mapped activity of cells sorted by correlation to lin (velM) or
% 2D (velP) run of various experiments (rd) or sites (proj_meta)
clims = [1 4]

figure('Position', [1 300 1600 550]), imagesc(proj_meta(3).rd(2).act(site(3).corr_matrix_lin_ind(2,:),:),clims)
figure('Position', [1 1 1600 250]),plot(xxx(1,:),proj_meta(3).rd(2).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(3).rd(2).velP_smoothed(1,:),'r')

figure('Position', [1 1 1600 250]),plot(xxx(1,:),proj_meta(3).rd(1).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(3).rd(1).velP_smoothed(1,:),'r')
box off
figure('Position', [1 300 1600 550])
subplot(3,1,1),plot(proj_meta(3).rd(1).act(53,:))
box off
subplot(3,1,2),plot(proj_meta(3).rd(1).act(65,:))
box off
subplot(3,1,3),plot(proj_meta(3).rd(1).act(114,:))
box off

subplot(2,2,1), imagesc(proj_meta(1).rd(1).act(site(1).corr_matrix_lin_ind(1,:),:),clims)
subplot(2,2,3), plot(xxx(1,:),proj_meta(1).rd(1).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(1).rd(1).velP_smoothed(1,:),'r')
subplot(2,2,2), imagesc(proj_meta(1).rd(2).act(site(1).corr_matrix_2D_ind(2,:),:),clims)
subplot(2,2,4), plot(xxx(1,:),proj_meta(1).rd(2).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(1).rd(2).velP_smoothed(1,:),'r')

subplot(2,3,1), imagesc(proj_meta(1).rd(1).act(site(1).corr_matrix_lin_ind(1,:),:),clims)
subplot(2,3,4), plot(xxx(1,:),proj_meta(1).rd(1).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(1).rd(1).velP_smoothed(1,:),'r')
subplot(2,3,2), imagesc(proj_meta(1).rd(2).act(site(1).corr_matrix_lin_ind(2,:),:),clims)
subplot(2,3,5), plot(xxx(1,:),proj_meta(1).rd(2).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(1).rd(2).velP_smoothed(1,:),'r')
subplot(2,3,3), imagesc(proj_meta(1).rd(2).act(site(1).corr_matrix_2D_ind(2,:),:),clims)
subplot(2,3,6), plot(xxx(1,:),proj_meta(1).rd(2).velM_smoothed(1,:),'b', xxx(1,:),proj_meta(1).rd(2).velP_smoothed(1,:),'r')

% correlation activity vs running, linear full line, 2D dashed of regions
% entered in site(#) structure
knd = [1:10]
figure
subplot(3,1,1), plot(knd(1,:), site(1).mean_corr_lin,'c',knd(1,:),site(1).mean_corr_2D,'-.m','LineWidth',2)
title('Region I'), set(gca,'XTickLabel',{'d1-lin','d1-2D','d2-lin','d2-2D','d3-lin','d3-2D','d4-lin','d4-2D','d5-lin','d5-2D'})
ylim = [0 0.2]
subplot(3,1,2), plot(knd(1,:), site(2).mean_corr_lin,'r',knd(1,:),site(2).mean_corr_2D,'-.g','LineWidth',2)
title('Region II'), set(gca,'XTickLabel',{'d1-lin','d1-2D','d2-lin','d2-2D','d3-lin','d3-2D','d4-lin','d4-2D','d5-lin','d5-2D'})
ylim = [0 0.2]
subplot(3,1,3), plot(knd(1,:), site(3).mean_corr_lin,'b',knd(1,:),site(3).mean_corr_2D,'-.k','LineWidth',2)
title('Region III'), set(gca,'XTickLabel',{'d1-lin','d1-2D','d2-lin','d2-2D','d3-lin','d3-2D','d4-lin','d4-2D','d5-lin','d5-2D'})
ylim = [0 0.2]

subplot(2,1,1), plot(proj_meta(2).rd(8).act(62,:))
subplot(2,1,2), plot(proj_meta(2).rd(8).velM(1,:))
